package cn;

import java.util.Scanner;

import javax.sound.sampled.LineListener;

public class SelectSort {
	int[] input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入数组长度：");
		int len = sc.nextInt();
		int[] arr = new int[len];
		System.out.println("请输入数组中的元素：");
		for (int i = 0; i < len; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	int[] sort(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					int temp = arr[j];
					arr[j] = arr[i];
					arr[i] = temp;
				}

			}
		}
		return arr;
	}

	void output(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.printf("%d\t", arr[i]);
		}
		System.out.println();
	}

	public static void main(String[] args) {
		SelectSort s = new SelectSort();
		int[] arr = s.input();
		s.output(arr);//输出原数组
		int[] newArr = s.sort(arr);
		s.output(arr);//输出新数组

	}

}
